'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    let resp = await this.service.helloService.echoHelloWorld();
    const { ctx } = this;
    ctx.body = resp;
  }

  async getUserFollowers(){
    let {user_name, page, per_page} = this.ctx.query;
    let resp = await this.service.githubService.getFollowers(user_name, page, per_page);
    this.ctx.body = resp;
  }

  async userFollowersList(){
    let {user_name, page, per_page} = this.ctx.query;
    let resp = await this.service.githubService.getFollowers(user_name, page, per_page);
    await this.ctx.render('userFollowers.ejs', {items: resp.data});
  }

  async randomApi(){
    let {ctx} = this;
    ctx.body = ctx.app.cache;
  }

  async respError401(){
    let {ctx} = this;
    // ctx.body = '';
    ctx.status = 401;
  }
}

module.exports = HomeController;
